#include <bits/stdc++.h>
using namespace std;

int a,n,b[1000010],d = -1;

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","W",stdout);
    scanf("%d" ,&a);
    while(a--){
        int c = 0;
        scanf("%d" ,&n);
        for(int i = 1;i <= n;i++){
            scanf("%d" ,&b[i]);
        }
        for(int i = 1;i <= n;i++)
            for(int j = i + 1;j <= n;j++)
                if(b[i] == b[j]){
                    c += b[j];
                    b[i] = --d;
                    b[j] = --d;
                }
        printf("%d\n" ,c);
    }
    return 0;
}
